package com.gmu.uav;

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.WindowManager;

public class MapViewActivity extends MapActivity implements LocationListener{
	
	private ArduinoConnection arduinoConn = null;
	private static final String TAG = "GMU ECE798 - Research Project UAV";
	private MapView mapView;
	private LocationManager locationManager = null;
	private MapController mapController = null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview_main);
        
        arduinoConn = (ArduinoConnection) getApplication();
        
        locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
       
        mapView = (MapView) findViewById(R.id.map_view); 
        mapView.setBuiltInZoomControls(true);
        mapView.setSatellite(false);
        mapView.setClickable(true);
        
        mapController = mapView.getController();
        mapController.setZoom(5);
	    
	    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
     
    }

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	 
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.global_menu, menu);
	    return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    // Handle item selection
	    switch (item.getItemId()) {
	        case R.id.switchToMap:
	    
	            return true;
	        case R.id.switchToFeed:
	            startActivity(new Intent(getApplicationContext(), VideoActivity.class));
	            return true;
	        case R.id.switchToController:
	            startActivity(new Intent(getApplicationContext(), ControllerActivity.class));
	            return true;
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}



	public void onLocationChanged(Location location) {
		if (location != null) {
			double lat = location.getLatitude();
			double lng = location.getLongitude();
			GeoPoint p = new GeoPoint((int) lat * 1000000, (int) lng * 1000000);
			
			mapController.animateTo(p);
		}
		
	}



	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}



	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}



	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}
    
}